<?php


namespace App\Service;

use _HumbugBox373c0874430e\Nette\Neon\Exception;
use App\Model\Enum\StatusEnum;

/**
 * Class MchConfigStatusService
 * 商户配置状态检查
 *
 * TODO 国际化
 *
 * @package App\Service
 */
class MchConfigStatusService {

    /**
     * 是否可用
     *
     * @param $mchConfig
     *
     * @throws \Exception
     */
    public function verifyAvailable ($mchConfig) {
        if (!$mchConfig) {
            throw new \Exception('商户配置信息不存在');
        }

        if ($mchConfig['status'] != StatusEnum::ON) {
            throw new \Exception('商户配置信息不可用');
        }
    }

    /**
     * 是否支持币种
     *
     * @param $mchConfig
     * @param $currency
     *
     * @throws \Exception
     */
    public function verifyTransCurrency ($mchConfig, $currency) {

        $this->verifyAvailable($mchConfig);

        $currencyArr = explode(',', $mchConfig['transCurrency']);

        if (!in_array($currency, $currencyArr)) {
            throw new \Exception('该商户不支持交易币种 ' . $currency);
        }
    }

}
